/*
 * @Author: 黄达全
 * @Date: 2024-08-28 16:55:23
 * @LastEditTime: 2024-08-29 17:52:47
 */
import axios from "../index"
import type { CategoryApi,CategoryTreeVO ,ApiResponse,CategoryPageVO,CategoryEditForm,CategoryAddForm} from "@/common/type"


export default {
    //获取树形的商品分类
    async tree() {
        return (await axios.get(`/admin/category`)).data as ApiResponse<CategoryTreeVO[]>
    },
    async select(parentId,page){
        return (await axios.get(`/admin/category/${parentId}?page=${page}`)).data as ApiResponse<CategoryPageVO>
    },

    async add(form: CategoryAddForm) {
        return (await axios.post(`/admin/category`, form)).data as ApiResponse<null>
    },
    async update(form: CategoryEditForm) {
        console.log(form);
        
        return (await axios.put(`/admin/category`, form)).data as ApiResponse<null>
    },
    async delete(ids: number[]) {
        const queryString = ids.map(id => `ids=${id}`).join('&');  
        return (await axios.delete(`/admin/category?${queryString}`)).data as ApiResponse<null>
    }
} as CategoryApi